#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;
  for (cin >> T; T; T--) {
    int n, q;
    string a, b;

    cin >> n >> q >> a >> b;

    vector<int> sum_a[26], sum_b[26];

    for (int i = 0; i < 26; i++) {
      sum_a[i].resize(n + 1, 0);
      sum_b[i].resize(n + 1, 0);
    }
    for (int i = 0; i < n; i++) {
      sum_a[a[i] - 'a'][i + 1] = 1;
      sum_b[b[i] - 'a'][i + 1] = 1;
    }
    for (int i = 0; i < 26; i++) {
      for (int j = 1; j <= n; j++) {
        sum_a[i][j] += sum_a[i][j - 1];
        sum_b[i][j] += sum_b[i][j - 1];
      }
    }
    for (int i = 0; i < q; i++) {
      int l, r;
      int ans = 0;

      cin >> l >> r;
      l--;
      for (int j = 0; j < 26; j++) {
        if (sum_a[j][r] - sum_a[j][l] > sum_b[j][r] - sum_b[j][l]) {
          ans += (sum_a[j][r] - sum_a[j][l]) - (sum_b[j][r] - sum_b[j][l]);
        }
      }
      cout << ans << "\n";
    }
  }
  return 0;
}